package com.windea.breezeframework.fxgl.extensions.input

import com.almasb.fxgl.input.*
import com.windea.breezeframework.fxgl.extensions.*

@FXGLDslMarker
fun userAction(name: String, builder: UserActionBuilder.() -> Unit = {}) = UserActionBuilder(name).also(builder).build()


class UserActionBuilder @PublishedApi internal constructor(
	private val name: String
) {
	private var begin: () -> Unit = {}
	
	private var action: () -> Unit = {}
	
	private var end: () -> Unit = {}
	
	fun onActionBegin(builder: () -> Unit) = run { begin = builder }
	
	fun onAction(builder: () -> Unit) = run { action = builder }
	
	fun onActionEnd(builder: () -> Unit) = run { end = builder }
	
	internal fun build() = object : UserAction(name) {
		override fun onActionBegin() = begin()
		
		override fun onAction() = action()
		
		override fun onActionEnd() = end()
	}
}
